﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using NTQOnlineExam.Services.EntityFW.Context;
using NTQOnlineExam.Services.Models;

namespace NTQOnlineExam.Services.ReportService.Year
{
    public class YearReportService : IYearReportService
    {
        public IList<YearDTO> GetAll()
        {
            using (var context = new ExamOnlineDbContext())
            {
                var years = context.Years.ToList();
                return years.Select(Mapper.Map<EntityFW.Entity.Year, YearDTO>).ToList();
            }
        }

        public YearDTO GetById(int yearId)
        {
            using (var context = new ExamOnlineDbContext())
            {
                var year = context.Years.Find(yearId);
                return Mapper.Map<EntityFW.Entity.Year, YearDTO>(year);
            }
        }

        public YearDTO GetByName(string yearName)
        {
            using (var context = new ExamOnlineDbContext())
            {
                var year = context.Years.FirstOrDefault(x => x.Name.Equals(yearName,StringComparison.InvariantCultureIgnoreCase));
                return Mapper.Map<EntityFW.Entity.Year, YearDTO>(year);
            }
        }
    }
}
